/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package model;

import Definitions.Globals;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;

/**
 *
 * @author Jirka
 */
@Entity
@Table(name = "stadium")
@NamedQueries({@NamedQuery(name = "Stadium.findAll", query = "SELECT s FROM Stadium s"), @NamedQuery(name = "Stadium.findByName", query = "SELECT s FROM Stadium s WHERE s.name = :name"), @NamedQuery(name = "Stadium.findByCapacity", query = "SELECT s FROM Stadium s WHERE s.capacity = :capacity"), @NamedQuery(name = "Stadium.findByEquipmentLevel", query = "SELECT s FROM Stadium s WHERE s.equipmentLevel = :equipmentLevel"), @NamedQuery(name = "Stadium.findByHomeClubId", query = "SELECT s FROM Stadium s WHERE s.homeClubId = :homeClubId")})
public class Stadium implements Serializable {
    private static final long serialVersionUID = 1L;
    @Column(name = "name")
    private String name;
    @Column(name = "capacity")
    private Integer capacity;
    @Column(name = "equipment_level")
    private Integer equipmentLevel;
    @Id
    @Basic(optional = false)
    @Column(name = "home_club_id")
    private Integer homeClubId;
    @JoinColumn(name = "home_club_id", referencedColumnName = "club_id", insertable = false, updatable = false)
    @OneToOne(optional = false)
    private Club club;

    public Stadium() {
        this.capacity = Globals.INIT_STADIUM_SEATS;
        this.equipmentLevel = Globals.INIT_EQUIPMENT_LEVEL;
    }

    public Stadium(Integer homeClubId) {
        this.homeClubId = homeClubId;
        this.capacity = Globals.INIT_STADIUM_SEATS;
        this.equipmentLevel = Globals.INIT_EQUIPMENT_LEVEL;
    }

    public void increaseCapacity(int seatCount) {
        this.capacity += seatCount;
    }

    public void improveEquipment() {
        this.equipmentLevel++;
    }

    public void rename(String newStadiumName) {
        this.name = newStadiumName;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getCapacity() {
        return capacity;
    }

    public void setCapacity(Integer capacity) {
        this.capacity = capacity;
    }

    public Integer getEquipmentLevel() {
        return equipmentLevel;
    }

    public void setEquipmentLevel(Integer equipmentLevel) {
        this.equipmentLevel = equipmentLevel;
    }

    public Integer getHomeClubId() {
        return homeClubId;
    }

    public void setHomeClubId(Integer homeClubId) {
        this.homeClubId = homeClubId;
    }

    public Club getClub() {
        return club;
    }

    public void setClub(Club club) {
        this.club = club;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (homeClubId != null ? homeClubId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Stadium)) {
            return false;
        }
        Stadium other = (Stadium) object;
        if ((this.homeClubId == null && other.homeClubId != null) || (this.homeClubId != null && !this.homeClubId.equals(other.homeClubId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "model.Stadium[homeClubId=" + homeClubId + "]";
    }

}
